﻿using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.FactoryCommand;
using B.S.Domain.Accounts;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.Management.SteamApplication.CommandHandler.FactoryCommandHandler
{
    public class FactoryUpdateCommandHandler : IRequestHandler<FactoryUpdateCommand, APIRequst<int>>
    {
        public FactoryUpdateCommandHandler(IBaseRepository<FactoryClass> factoryRepository)
        {
            FactoryRepository = factoryRepository;
        }

        public IBaseRepository<FactoryClass> FactoryRepository { get; }

        public async Task<APIRequst<int>> Handle(FactoryUpdateCommand request, CancellationToken cancellationToken)
        {
            request.Data.UpdateTime = DateTime.UtcNow;
            return Task.FromResult(new APIRequst<int> { Code = RequstCode.成功, Msg = "工厂信息更新成功", Data = await FactoryRepository.Update(request.Data) }).Result ;
        }
    }
}
